package algotithm.leetcode.math.test168;

/**
 * @author zhouyanxiang
 * @Date 2021-04-2021/4/1-23:26
 * @Title 168. Excel表列名称
 */
class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int n = 27;
        String s = solution.convertToTitle(n);
        System.out.println(s);
    }

    public String convertToTitle(int n) {
        StringBuilder sb = new StringBuilder();
        while (n > 0) {
            int c = n % 26;
            if(c == 0){
                c = 26;
                n -= 1;
            }
            sb.insert(0, (char) ('A' + c - 1));
            n /= 26;
        }
        return sb.toString();
    }

}